package com.cnseedlingscloud.draw.prize.dao;


import com.cnseedlingscloud.draw.prize.entity.TurntableRecord;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface TurntableRecordDao {

    @Results(id = "turntableRecordMap", value = {
            @Result(property = "id", column = "id", id = true),
            @Result(property = "drawId", column = "draw_id"),
            @Result(property = "prizeName", column = "prize_name"),
            @Result(property = "phone", column = "phone")
    })
    @Insert("insert into turntable_record(draw_id,prize_name,phone) values(#{drawId},#{prizeName},#{phone})")
    @Options(useGeneratedKeys=true, keyProperty="id", keyColumn="id")
    Integer save(TurntableRecord turntableRecord);


    @Select("select id,draw_id,prize_name,phone   from turntable_record order by id")
    List<TurntableRecord> queryAll();

    @Select("SELECT  PRIZE_NUM-COUNT(B.ID)  FROM TURNTABLE_DRAW  a LEFT JOIN TURNTABLE_RECORD b " +
            "ON A.ID=B.DRAW_ID WHERE A.ID=#{drawId}")
    Integer  queryRemain(Long drawId);



}
